package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhCar;
import com.laowang.project.system.service.MyCyhCarService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 我的爱车Controller
 *
 * @author laowang
 * @date 2023-05-09
 */
@Api(tags = "我的爱车接口")
@RestController
@RequestMapping("/myCar")
public class MyCyhCarController extends BaseController {
    @Autowired
    private MyCyhCarService myCyhCarService;

    /**
     * 查询我的爱车列表
     */
    @ApiOperation(value = "小程序端 查询我的爱车列表",notes = "")
    @GetMapping("/web/all")
    public AjaxResult all() {
        Integer mid = SecurityUtils.getLoginUser().getWxUser().getMid();
        MyCyhCar myCyhCar =new MyCyhCar();
        myCyhCar.setUserId(mid);
        List<MyCyhCar> list = myCyhCarService.selectMyCyhCarList(myCyhCar);
        return AjaxResult.success("操作成功",list);
    }

    /**
     * 新增我的爱车
     */
    @ApiOperation(value = "小程序端 新增我的爱车",notes = "")
    @PostMapping("/web/add")
    public AjaxResult webAdd(@RequestBody MyCyhCar myCyhCar) {
        return toAjax(myCyhCarService.insertMyCyhCarWeb(myCyhCar));
    }


    /**
     * 查询我的爱车列表
     */
    @ApiOperation(value = "查询我的爱车列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myCar:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCyhCar myCyhCar) {
        startPage();
        List<MyCyhCar> list = myCyhCarService.selectMyCyhCarList(myCyhCar);
        return getDataTable(list);
    }

    /**
     * 导出我的爱车列表
     */
    @ApiOperation(value = "导出我的爱车列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myCar:export')")
    @Log(title = "我的爱车", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyCyhCar myCyhCar) {
        List<MyCyhCar> list = myCyhCarService.selectMyCyhCarList(myCyhCar);
        ExcelUtil<MyCyhCar> util = new ExcelUtil<MyCyhCar>(MyCyhCar.class);
        return util.exportExcel(list, "myCar");
    }

    /**
     * 获取我的爱车详细信息
     */
    @ApiOperation(value = "获取我的爱车详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myCar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myCyhCarService.selectMyCyhCarById(id));
    }

    /**
     * 新增我的爱车
     */
    @ApiOperation(value = "新增我的爱车",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myCar:add')")
    @Log(title = "我的爱车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhCar myCyhCar) {
        return toAjax(myCyhCarService.insertMyCyhCar(myCyhCar));
    }

    /**
     * 修改我的爱车
     */
    @ApiOperation(value = "修改我的爱车",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myCar:edit')")
    @Log(title = "我的爱车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhCar myCyhCar) {
        return toAjax(myCyhCarService.updateMyCyhCar(myCyhCar));
    }

    /**
     * 删除我的爱车
     */
    @ApiOperation(value = "删除我的爱车",notes = "")
    @PreAuthorize("@ss.hasPermi('my:myCar:remove')")
    @Log(title = "我的爱车", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhCarService.deleteMyCyhCarByIds(ids));
    }
}
